;;;
;;; JaCoLiB
;;; Copyright (C) 2008 Alessandro Serra
;;; 
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;; 
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;; 
;;; You should have received a copy of the GNU General Public License
;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
;;;

;;;; Created on 2008-07-02 10:44:17

(in-package :jacolib)

;
; Remote Shell
;

(defclass remote-shell (shell rpc-client)
  ((name
    :TYPE string
    :INITARG :name
    :READER remote-shell-name))
  (:documentation "A remote shell. It is a proxy. 
When it receives a message it transforms the message into a pair (method, parameters) 
that will be sent the rpc client stub."))

; methods

(defmethod shell-hello ((shell remote-shell))
  (rpc-client-exec shell "shell-hello" nil))

(defmethod shell-language-name ((shell remote-shell))
  (rpc-client-exec shell "shell-language-name" nil))

(defmethod shell-get ((shell remote-shell) (key string))
  (rpc-client-exec shell "shell-get" (list key)))

(defmethod shell-set ((shell remote-shell) (key string) obj)
  (rpc-client-exec shell "shell-set" (list key obj)))

(defmethod shell-unset ((shell remote-shell) (key string))
  (rpc-client-exec shell "shell-unset" (list key)))

(defmethod shell-eval ((shell remote-shell) (code string))
  (rpc-client-exec shell "shell-eval" (list code)))

(defmethod shell-source ((shell remote-shell) (filename string))
  (rpc-client-exec shell "shell-source"  (list filename)))

(defun remote-shell-quit (shell)
  (rpc-client-quit shell))

(defmethod rpc-client-quit% ((client remote-shell))
  (declare (ignore client))
  (call-next-method))

